<?php
session_start();
if (!isset($_SESSION['admin']))
    header('location:index.php');
ob_start();
?>

<!DOCTYPE HTML>
<html>

    <head>
        <title>3D|Didongday 3D- Di động đây</title>
        <?php include('modules/page_head.php'); ?>
    </head>

    <body>
        <div id="main">
            <div id="header">
                <div id="logo">
                    <h1><a href="index.php">Didongde</a></h1>
                    <div class="slogan">Where you can find your own best suitable mobile</div>
                    <?php include_once('modules/logo_header.php'); ?>
                </div>
                <div id="menubar">
                    <?php include_once('modules/menubar.php'); ?>
                </div>
            </div>
            <div id="site_content">
                <div id="sidebar_container">
                    <h2>Tìm kiếm nhanh</h2>
                    <div class="sidebar">
                        <!-- insert your sidebar items here -->
                        <?php
                        include ("modules/quick_search.php");
                        show_manu();
                        ?>
                    </div>
                    <div class="sidebar">
                        <?php show_price(); ?>
                    </div>
                </div>
                <div id="content">
                    <!-- insert the page content here -->
                    <?php
                    /* connect to database server */
                    include_once('conf/dbconfig.php');
                    $cfg = new dbconfig();
                    $host = $cfg->get_dbhost();
                    $db = $cfg->get_dbname();
                    $usr = $cfg->get_dbusername();
                    $pass = $cfg->get_dbpwd();
                    $connection = pg_connect("host = $host dbname = $db user = $usr password = $pass")
                            or die("Cannot connect to database server");
                    ?>
                    <h1>Thay đổi thông tin nhà cung cấp</h1>
                    <div>
                        <form action="#" method="post">
                            Tên nhà cung cấp : <big><b>
                                    <?php
                                    $query = "select * from manufacturer order by name";
                                    $result = pg_query($connection, $query);
                                    echo "<select id=\"select_id\" name = \"manu\">";
                                    echo "<option value=-1>Chọn nhà cung cấp</option>";
                                    for ($i = 0; $i < pg_num_rows($result); $i++) {
                                        $mid = pg_fetch_result($result, $i, 'manuid');
                                        $name = pg_fetch_result($result, $i, 'name');
                                        echo "<option value = \"$mid\"";
                                        if (isset($_REQUEST['manu']) && $_REQUEST['manu'] == $mid) {
                                            echo "selected=\"selected\"";
                                            setcookie("manuid", $mid, time() + 3600);
                                            ob_end_flush();
                                        }
                                        echo ">$name</option>";
                                        echo "</option>";
                                    }
                                    echo "</select>";
                                    pg_free_result($result);
                                    ?>
                                </b></big>
                            <input type="submit" value="Chọn" name="select" style="padding:2px 5px 2px 5px;"/>
                            <hr/><br>
                        </form>
                        <?php
                        if (isset($_REQUEST['select'])) {
                            $manu = $_POST['manu'];
                            if ($manu != -1) {
                                $query = "select * from manufacturer where manuid = '$manu'";
                                $result = pg_query($connection, $query);
                                ?>
                                <form class="form_settings" action="manufacturer_process.php" method="post">
                                    <table>
                                        <tr >
                                            <td colspan="2">Thông tin nhà sản xuất</td></tr>
                                        <tr >
                                            <td colspan="2"><h4>*Bạn có thể thay đổi thông tin nhà cung cấp</h4></td></tr>
                                        <tr><td>Tên nhà cung cấp</td><td>
                                                <input type="text" name="name" value="<?php echo pg_fetch_result($result, 0, 'name'); ?>"/>
                                            </td></tr>
                                        <tr><td>E-mail</td><td>
                                                <input type="email" class="email" name="email" value="<?php echo pg_fetch_result($result, 0, 'email'); ?>"/>
                                            </td></tr>
                                        <tr><td>Địa chỉ</td><td>
                                                <input type="text" name="addr" value="<?php echo pg_fetch_result($result, 0, 'address'); ?>" />
                                            </td></tr>
                                        <tr><td>Số điện thoại</td><td>
                                                <input type="tel" name="phone" value="<?php echo pg_fetch_result($result, 0, 'phone_number'); ?>"/>
                                            </td></tr>
                                    </table>
                                    <input class="submit" type="submit" value="Xác nhận" name="confirm" />
                                    <hr/>
                                </form>
                                <?php
                            }
                        }
                        ?>
                    </div>
                </div>
            </div>
            <div id="footer">
                <?php include('modules/footer.php'); ?>
            </div>
        </div>
    </body>
</html>
